﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace CXMLStudioIDE.Common
{
    public class ChangeCtrlPropertyCommand : UndoCommand
    {
        // Fields
        private object[] m_ctrls;
        private object m_newValue;
        private object m_oldValue;
        private string m_propName;

        // Methods
        public ChangeCtrlPropertyCommand(object[] ctrls, string propName, object oldValue, object newValue)
        {
            this.m_ctrls = ctrls;
            this.m_propName = propName;
            this.m_oldValue = oldValue;
            this.m_newValue = newValue;
        }

        public override void Redo()
        {
            try
            {
                foreach (object obj2 in this.m_ctrls)
                {
                    TypeDescriptor.GetProperties(obj2).Find(this.m_propName, true).SetValue(obj2, this.m_newValue);
                }
                //MainForm.m_propertyWindow.SetSelectedObjects(this.m_ctrls);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Redo ChangeCtrlProperty Failed:" + exception.Message);
            }
        }

        public override void Undo()
        {
            try
            {
                foreach (object obj2 in this.m_ctrls)
                {
                    TypeDescriptor.GetProperties(obj2).Find(this.m_propName, true).SetValue(obj2, this.m_oldValue);
                }
                //MainForm.m_propertyWindow.SetSelectedObjects(this.m_ctrls);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Undo ChangeCtrlProperty Failed:" + exception.Message);
            }
        }
    }

 

}
